#include "BatchCheckInResponseModel.h"
using namespace MesModel;

BatchCheckInResponseModel::BatchCheckInResponseModel() {}

void BatchCheckInResponseModel::fromJson(const QJsonObject &json)
{
    factoryNo = json["factoryNo"].toString();
    transId = json["transId"].toString();
    eventTime.fromString(json["eventTime"].toString());
    resultCode = json["resultCode"].toString();

    QJsonArray pcuInfoArray = json["pcuInfo"].toArray();
    for(const auto& item:qAsConst(pcuInfoArray))
    {
        BatchCheckInResponsePcuInfo pcu_info;
        pcu_info.fromJson(item.toObject());
        pcuInfo.append(pcu_info);

    }
}

QJsonObject BatchCheckInResponseModel::toJson() const
{
    QJsonObject json;

    int randomNumber = QRandomGenerator::global()->bounded(10000,100000);

    json["factoryNo"] = factoryNo;
    json["transId"] = QString("%1%2").arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmssSSS")).arg(randomNumber);
    json["eventTime"] = QDateTime::currentDateTime().toString("yyyy-mm-dd hh:mm:ss");
    json["resultCode"] = resultCode;

    QJsonArray pcuInfoArray;
    for(const auto&item:pcuInfo)
    {
        pcuInfoArray.append(item.toJson());
    }
    json["pcuInfo"] = pcuInfoArray;
    return json;
}


void BatchCheckInResponsePcuInfo::fromJson(const QJsonObject &json)
{
    locationNo = json["locationNo"].toString();
    pcu = json["pcu"].toString();
    resultMsg = json["resultMsg"].toString();
}

QJsonObject BatchCheckInResponsePcuInfo::toJson() const
{
    QJsonObject json;
    json["locationNo"] = locationNo;
    json["pcu"] = pcu;
    json["resultMsg"] = resultMsg;

    return json;
}
